package com.summer.study.leetcode.simple_class;

/**
 * @auther: 杨杰
 * @date: 2019/7/26 14:48
 * @description:
 */
public class ListNode {

    int val;

    ListNode next;

    public ListNode(int x) {
        val = x;
    }

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }


    static ListNode reverseList(ListNode head) {
        ListNode curr=head;
        ListNode prev=null;
        while(curr!=null){
            ListNode nextTemp = curr.next;
            curr.next = prev;
            prev = curr;
            curr = nextTemp;
        }
        return curr;
    }


    public static void main(String[] args) {
        ListNode node3=new ListNode(3);
        ListNode node2=new ListNode(2,node3);
        ListNode node1=new ListNode(1,node2);



        reverseList(node1);
        System.out.println(node3.next.val);
    }
}
